package day04;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/12
 */

//需求3：二维数组3X3，求其对角线元素之和

public class TestDoubleArray03 {
    public static void main(String[] args) {
        int[][] arr={{1,2,3},{4,5,6},{7,8,9}};
/*        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+"\t");
            }
            System.out.println();
        }*/

        int sum1=0;
        int sum2=0;

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                //正对角线
                if(i==j){
                    sum1+=arr[i][j];
                }
                //副对角线
                if(i+j==arr.length-1){
                    sum2+=arr[i][j];
                }
            }
        }
        System.out.println("sum1="+sum1);
        System.out.println("sum2="+sum2);
    }
}
